<?php

/**
 * 题库题目浏览
 */
class RplistController extends ApplicationController
{

    public function init()
    {
        Yaf\Dispatcher::getInstance()->enableView();
    }

    public function indexAction()
    {
        $table = 'rp0403.question-t-gz';

        $pageNum = $this->get('pageNum');
        $offset  = $this->get('offset');
        $limit   = $this->get('limit');
        if ($pageNum === false) {
            $pageNum = $this->post('pageNum');
        }
        if ($offset === false) {
            $offset = $this->post('offset');
        }
        if ($limit === false) {
            $limit = $this->post('limit');
        }

        if ($pageNum === false) $pageNum = 1;
        if ($offset === false) $offset = 0;
        if ($limit === false) $limit = 10;

        $stage   = $this->post('stage');
        $grade   = $this->post('grade');
        $subject = $this->post('subject');

        $where = [];
        if ($stage !== false && $stage !== '') $where['grade'] = $stage;
        if ($grade !== false && $grade !== '') $where['class'] = $grade;
        if ($subject !== false && $subject !== '') $where['subject'] = $subject;

        if ($stage === false) $stage = 'chuzhong';
        if ($stage === 'xiaoxue') {
            $table = 'rp0403.question-t-xx';
        } elseif ($stage === 'chuzhong') {
            $table = 'rp0403.question-t-cz';
        } elseif ($stage === 'gaozhong') {
            $table = 'rp0403.question-t-gz';
        }

        $data = TestTikuXx01Model::getAll($table, 'id, stem as questionTrunk, answer, analysis, difficulty, subject, grade, class, type as questionType, date as createDate', $where, $offset, $limit);
        $this->getView()->assign("offset", $offset);
        $this->getView()->assign("limit", $limit);
        $this->getView()->assign("pageNum", $pageNum);
        $this->getView()->assign("list", $data);

        $this->getView()->assign("stage", $stage);
        $this->getView()->assign("grade", $grade);
        $this->getView()->assign("subject", $subject);
    }

    public function cgzAction()
    {
        $table = 'rp.sh_testquestion_5000';

        $pageNum = $this->get('pageNum');
        $offset  = $this->get('offset');
        $limit   = $this->get('limit');
        if ($pageNum === false) {
            $pageNum = $this->post('pageNum');
        }
        if ($offset === false) {
            $offset = $this->post('offset');
        }
        if ($limit === false) {
            $limit = $this->post('limit');
        }

        if ($pageNum === false) $pageNum = 1;
        if ($offset === false) $offset = 0;
        if ($limit === false) $limit = 10;

        $stage   = $this->post('stage');
        $grade   = $this->post('grade');
        $subject = $this->post('subject');

        $where = [];
        if ($stage !== false && $stage !== '') $where['gradeid'] = $stage;
        if ($grade !== false && $grade !== '') $where['gradeid'] = $grade;
        if ($subject !== false && $subject !== '') $where['subjectid'] = $subject;

        if ($stage === false) $stage = 'chuzhong';

//        1008 初一、1009 初二、1010 初三、1011 高一   1012 高二   1013 高三
        $data = TestTikuXx01Model::getAll($table, 'id, content as questionTrunk, answerContent as answer, analytical as analysis, complexity as difficulty, subjectid as subject, gradeid as grade, tqtid as questionType, year as createDate', $where, $offset, $limit, 'id asc');
        $this->getView()->assign("offset", $offset);
        $this->getView()->assign("limit", $limit);
        $this->getView()->assign("pageNum", $pageNum);
        $this->getView()->assign("list", $data);

        $this->getView()->assign("stage", $stage);
        $this->getView()->assign("grade", $grade);
        $this->getView()->assign("subject", $subject);
    }

    public function qpAction()
    {
        $table = 'zj_question_7';

        $pageNum = $this->get('pageNum');
        $offset  = $this->get('offset');
        $limit   = $this->get('limit');
        if ($pageNum === false) {
            $pageNum = $this->post('pageNum');
        }
        if ($offset === false) {
            $offset = $this->post('offset');
        }
        if ($limit === false) {
            $limit = $this->post('limit');
        }

        if ($pageNum === false) $pageNum = 1;
        if ($offset === false) $offset = 0;
        if ($limit === false) $limit = 10;

        $stage   = $this->post('stage');
        $grade   = $this->post('grade');
        $subject = $this->post('subject');

        $where = [];

        if ($stage === false) $stage = '2';

        if ($stage !== false && $stage !== '') {
//            10010 语文  10011 数学  10012 英语  10013 生物   10014  物理   10015 化学  10016 地理  10017 历史   10018 政治
            if ($stage == '1' && $subject == '10010') {//小学语文
                $table = 'zj_question_24';
            } elseif ($stage == '1' && $subject == '10011') {
                $table = 'zj_question_23';
            } elseif ($stage == '1' && $subject == '10012') {
                $table = 'zj_question_25';
            } elseif ($stage == '2' && $subject == '10010') {//初中语文
                $table = 'zj_question_1';
            } elseif ($stage == '2' && $subject == '10011') {//数学
                $table = 'zj_question_2';
            } elseif ($stage == '2' && $subject == '10012') {//英语
                $table = 'zj_question_3';
            } elseif ($stage == '2' && $subject == '10014') {
                $table = 'zj_question_4';
            } elseif ($stage == '2' && $subject == '10015') {
                $table = 'zj_question_5';
            } elseif ($stage == '2' && $subject == '10013') {
                $table = 'zj_question_6';
            } elseif ($stage == '2' && $subject == '10018') {
                $table = 'zj_question_7';
            } elseif ($stage == '2' && $subject == '10017') {
                $table = 'zj_question_8';
            } elseif ($stage == '2' && $subject == '10016') {
                $table = 'zj_question_9';
            } elseif ($stage == '3' && $subject == '10010') {//高中语文
                $table = 'zj_question_10';
            } elseif ($stage == '3' && $subject == '10011') {
                $table = 'zj_question_11';
            } elseif ($stage == '3' && $subject == '10012') {
                $table = 'zj_question_12';
            } elseif ($stage == '3' && $subject == '10014') {
                $table = 'zj_question_13';
            } elseif ($stage == '3' && $subject == '10015') {
                $table = 'zj_question_14';
            } elseif ($stage == '3' && $subject == '10013') {
                $table = 'zj_question_15';
            } elseif ($stage == '3' && $subject == '10018') {
                $table = 'zj_question_16';
            } elseif ($stage == '3' && $subject == '10017') {
                $table = 'zj_question_17';
            } elseif ($stage == '3' && $subject == '10016') {//高中地理
                $table = 'zj_question_18';
            } elseif ($stage == '3' && $subject == '10019') {//初中科学
                $table = 'zj_question_26';
            } elseif ($stage == '3' && $subject == '10021') {//高中信息技术
                $table = 'zj_question_27';
            } elseif ($stage == '3' && $subject == '10022') {//高中通用技术
                $table = 'zj_question_28';
            } elseif ($stage == '3' && $subject == '10021') {//初中信息技术
                $table = 'zj_question_28';
            }
        }


//        1008 初一、1009 初二、1010 初三、1011 高一   1012 高二   1013 高三
        $data = TestTikuXx01Model::getAll($table, 'id, question_body as questionTrunk, question_answer as answer, question_parse as analysis, "无" as difficulty, "'.$subject.'" as subject, "无" as grade, 1 as questionType, "无" as createDate', $where, $offset, $limit, 'id asc');
        $this->getView()->assign("offset", $offset);
        $this->getView()->assign("limit", $limit);
        $this->getView()->assign("pageNum", $pageNum);
        $this->getView()->assign("list", $data);

        $this->getView()->assign("stage", $stage);
        $this->getView()->assign("grade", $grade);
        $this->getView()->assign("subject", $subject);
    }

}
